package com.ekuaitu.kuaitu.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ekuaitu.kuaitu.R;
import com.ekuaitu.kuaitu.bean.MyInvoiceHistoryBean;
import com.ekuaitu.kuaitu.utils.TimeUtils;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by CaoJing on 2016/10/5.
 */
public class MyInvoiceHistoryLvAdapter extends BaseAdapter {
    private List<MyInvoiceHistoryBean.AttachmentBean.InvoiceApplyModelsBean> mlist;
    private Context mContext;

    public MyInvoiceHistoryLvAdapter(List<MyInvoiceHistoryBean.AttachmentBean.InvoiceApplyModelsBean> list, Context context) {
        this.mlist = list;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return mlist != null ? mlist.size() : 0;
    }

    @Override
    public Object getItem(int i) {
        return mlist != null ? mlist.get(i) : null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.invoice_history_lv_item, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
            //对于listview，注意添加这一行，即可在item上使用高度
            AutoUtils.autoSize(convertView);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        MyInvoiceHistoryBean.AttachmentBean.InvoiceApplyModelsBean item = mlist.get(position);
        if (item.getStatus()==0){
            holder.invoiceLvHistoryItemTvStatus.setText("未发出");
            holder.invoiceLvHistoryItemTvStatus.setTextColor(Color.RED);
        }else if (item.getStatus()==1){
            holder.invoiceLvHistoryItemTvStatus.setText("已发出");
            holder.invoiceLvHistoryItemTvStatus.setTextColor(Color.GREEN);
        }
        holder.invoiceLvHistoryItemTvMoney.setText(item.getApplyMount());
        holder.invoiceLvHistoryItemTvTime.setText(TimeUtils.getFormatDate(item.getCreateTime(),"yyyy-MM-dd   HH:mm"));
        return convertView;
    }


    static class ViewHolder {
        @BindView(R.id.invoice_lv_history_item_tvMoney)
        TextView invoiceLvHistoryItemTvMoney;
        @BindView(R.id.invoice_lv_history_item_ll)
        AutoLinearLayout invoiceLvHistoryItemLl;
        @BindView(R.id.invoice_lv_history_item_tvTime)
        TextView invoiceLvHistoryItemTvTime;
        @BindView(R.id.invoice_lv_history_item_tvStatus)
        TextView invoiceLvHistoryItemTvStatus;
        @BindView(R.id.invoice_lv_history_item_iv)
        ImageView invoiceLvHistoryItemIv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}

